package com.example.flowermall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.flowermall.entity.Members;
import com.example.flowermall.mapper.MembersMapper;
import com.example.flowermall.service.MembersService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Members)表服务实现类
 *
 * @author mq
 * @since 2025-02-11 09:50:57
 */
@Service("membersService")
public class MembersServiceImpl implements MembersService {
    @Resource
    private MembersMapper membersMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Members queryById(Integer id) {
        return this.membersMapper.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param members 实例对象
     * @return 实例对象
     */
    @Override
    public Members insert(Members members) {
        membersMapper.insert(members);
        return members;
    }

    /**
     * 修改数据
     *
     * @param members 实例对象
     * @return 实例对象
     */
    @Override
    public Members update(Members members) {
        this.membersMapper.update(members);
        return this.queryById(members.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.membersMapper.deleteById(id) > 0;
    }

    @Override
    public List<Members> getIntegralList(Integer id) {
        LambdaQueryWrapper<Members> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Members::getUid,id);
        queryWrapper.eq(Members::getType,2);
        return membersMapper.selectList(queryWrapper);
    }

    @Override
    public List<Members> getBalanceList(Integer id) {
        LambdaQueryWrapper<Members> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Members::getUid,id);
        queryWrapper.eq(Members::getType,1);
        return membersMapper.selectList(queryWrapper);
    }

    @Override
    public Integer getByOrderId(String orderId) {
        LambdaQueryWrapper<Members> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Members::getOrderId,orderId);
        List<Members> membersList = membersMapper.selectList(queryWrapper);
        if(membersList.size()==1){
            return 1;
        }
        return 0;
    }
}
